//
//  WSForumDetailsCell.m
//  RunningMan
//
//  Created by 王帅 on 16/5/19.
//  Copyright © 2016年 WSJ. All rights reserved.
//

#import "WSForumDetailsCell.h"
#import "WSMyTool.h"
#import "WSAFNetWorkingTool.h"

@interface WSForumDetailsCell ()
@property (nonatomic, strong) UIImageView *imageViewPhoto;
@property (nonatomic, strong) UIImageView *imageViewUse;
@property (nonatomic, strong) UILabel *lableCommenty;
@property (nonatomic, strong) UILabel *lableUserName;
@property (nonatomic, strong) UILabel *lableTime;
@property (nonatomic, strong) UILabel *lablePra;
@property (nonatomic, strong) UILabel *lableToUse;
@end

@interface WSForumDetailsCell ()
@property (nonatomic, assign)CGFloat heightComment;

@end

@implementation WSForumDetailsCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        [self createSubView];
    }
    
    return self;
}

- (void)setModelUse:(WSForumModel *)modelUse{
    _modelUse = modelUse;
    self.lableUserName.text = modelUse.username;
    NSArray *arr = [modelUse.avatar componentsSeparatedByString:@"/"];
    NSString *url = [NSString stringWithFormat:@"http://%@.fit-time.cn/%@", arr[0], arr[1]];
    [self.imageViewUse sd_setImageWithURL:[NSURL URLWithString:url] placeholderImage:[UIImage imageNamed:@"允儿副本.jpg"]];
    
}

- (void)setModelHot:(WSForumModel *)modelHot{
    _modelHot = modelHot;
    // 时间
    NSString *creatTime = [[NSString stringWithFormat:@"%@", modelHot.createTime] substringToIndex:10];
    NSDate *confromTimesp = [NSDate dateWithTimeIntervalSince1970:[creatTime doubleValue]];
    NSString *time = [[NSString stringWithFormat:@"%@", confromTimesp] substringWithRange:NSMakeRange(0, 19)];
    NSString *strTime = [NSString stringWithFormat:@"%@月%@日", [time substringWithRange:NSMakeRange(5, 2)], [time substringWithRange:NSMakeRange(8, 2)]];
    self.lableTime.text = strTime;
    
    
    self.lablePra.text = [NSString stringWithFormat:@"赞: %@", modelHot.praiseCount];
    
    self.lableCommenty.text = modelHot.comment;
    self.heightComment  =  [WSAFNetWorkingTool getSuitableHeightOfLableContentString:modelHot.comment OringeWidth:344 Font:[UIFont systemFontOfSize:17]];
    CGRect frameComment = self.lableCommenty.frame;
    frameComment.size.height = self.heightComment;
    self.lableCommenty.frame = frameComment;
    
    if ([modelHot.userId isEqual:modelHot.toUserId]) {
        self.lableToUse.text = modelHot.comment;
        CGFloat heightToUse = [WSAFNetWorkingTool getSuitableHeightOfLableContentString:modelHot.comment OringeWidth:394 Font:[UIFont systemFontOfSize:17]];
        CGRect frameToUse = self.lableToUse.frame;
        frameToUse.size.height = heightToUse;
        self.lableToUse.frame = frameToUse;
    }
    
    
}

- (void)createSubView {
    
    self.imageViewUse = [[UIImageView alloc] initWithFrame:CGRectZero];
    self.imageViewUse.contentMode = UIViewContentModeScaleToFill;
    self.imageViewUse.layer.cornerRadius = 25;
    self.imageViewUse.layer.masksToBounds = YES;
    [self.contentView addSubview:self.imageViewUse];
    
    
    
    self.lableUserName = [[UILabel alloc] initWithFrame:CGRectZero];
    self.lableUserName.font = [UIFont systemFontOfSize:17];
    [self.contentView addSubview:self.lableUserName];
    
    self.lableTime = [[UILabel alloc] initWithFrame:CGRectZero];
    self.lableTime.font = [UIFont systemFontOfSize:14];
    self.lableTime.textColor = [UIColor grayColor];
    [self.contentView addSubview:self.lableTime];
    
    self.lableCommenty  = [[UILabel alloc] initWithFrame:CGRectMake(10, 70, 394, 1)];
    self.lableCommenty.font = [UIFont systemFontOfSize:17];
    self.lableCommenty.numberOfLines = 0;
    [self.contentView addSubview:self.lableCommenty];
    
    self.lablePra = [[UILabel alloc] initWithFrame:CGRectZero];
    self.lablePra.font = [UIFont systemFontOfSize:17];
    self.lablePra.textColor = [UIColor grayColor];
    [self.contentView addSubview:self.lablePra];
    
    self.lableToUse = [[UILabel alloc] initWithFrame:CGRectZero];
    self.lableToUse.backgroundColor = [UIColor grayColor];
    self.lableToUse.alpha = 0.7;
    self.lableToUse.numberOfLines = 0;
    self.lableToUse.font = [UIFont systemFontOfSize:17];
    [self.contentView addSubview:self.lableToUse];
    
    
}

- (void)layoutSubviews{
    [super layoutSubviews];
    self.imageViewUse.frame = CGRectMake(10, 10, 50, 50);
    self.lableUserName.frame = CGRectMake(70, 10, 200, 30);
    self.lableTime.frame = CGRectMake(70, 40, 200, 20);
    self.lablePra.frame = CGRectMake(344, 10, 70, 30);
}


- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
